package com.csun.cmny.provider.controller;

import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.dto.BedSortSaveDto;
import com.csun.cmny.provider.model.vo.BedSortVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OmcBedSortService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-03-11 13:15
 * @Description: the class omc bed sort controller
 */
@RestController
@RequestMapping(value = "/bed", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OmcBedSortController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @Resource
    private OmcBedSortService omcBedSortService;

    /**
     * 根据roomId查询房间排序
     *
     * @param roomId    room id
     *
     * @return  the wrapper.
     */
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @PostMapping(value = "/queryBedSortByRoomId/{roomId}")
    public Wrapper queryBedSortByRoomId(@PathVariable Integer roomId) {

        BedSortVo bedSortVo = omcBedSortService.queryBedSortByRoomId(roomId);

//        return WrapMapper.ok(bedSortVo);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource.getMessage("operation.success", null), bedSortVo);
    }

    /**
     * 保存床位排序
     *
     * @param bedSortSaveDto    save bed sort dto
     * @param br                binging result
     *
     * @return  the wrapper
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @PostMapping(value = "/saveBedSort")
    public Wrapper saveBedSort(@Validated @RequestBody BedSortSaveDto bedSortSaveDto, BindingResult br) {

        Integer result = omcBedSortService.saveBedSort(bedSortSaveDto, getLoginAuthDto());
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }
//        return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource.getMessage("operation.success", null), result);
    }

}
